package com.qujia.station.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qujia.common.annotation.Log;
import com.qujia.common.constant.UserConstants;
import com.qujia.common.core.controller.BaseController;
import com.qujia.common.core.domain.AjaxResult;
import com.qujia.common.core.domain.entity.SysUser;
import com.qujia.common.core.domain.model.LoginUser;
import com.qujia.common.core.page.TableDataInfo;
import com.qujia.common.core.redis.RedisCache;
import com.qujia.common.enums.BusinessType;
import com.qujia.common.enums.ErrorCode;
import com.qujia.common.exception.CustomException;
import com.qujia.common.utils.SecurityUtils;
import com.qujia.common.utils.StringUtils;
import com.qujia.station.domain.*;
import com.qujia.station.domain.dto.AddStationDto;
import com.qujia.station.domain.dto.AddStationSettleInfoDto;
import com.qujia.station.domain.vo.*;
import com.qujia.station.service.*;
import com.qujia.system.mapper.SysUserMapper;
import com.qujia.system.service.ISysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 油站信息Controller
 *
 * @author qujia
 * @date 2020-12-08
 */
@RestController
@RequestMapping("/station/message")
@Api(tags = "油站信息Controller", description = "油站信息")
@Slf4j
public class StationController extends BaseController
{
    @Autowired
    private IStationService stationService;
    @Autowired
    private IPayStationBetweenService payStationBetweenService;
    @Autowired
    private ISysUserService sysUserService;
    @Autowired
    private SysUserMapper userMapper;
    @Autowired
    private RedisCache redisCache;

    @Autowired
    private IPayWayService payWayService;

    @Autowired
    private IEnterpriseService enterpriseService;
    @Autowired
    private IStaffService staffService;

    @Autowired
    private RepositoryService repositoryService;

    /**
     * 查询油站信息列表
     */
    @GetMapping("/transactionStationList")
    @ApiOperation(value = "查询分账油企信息列表", notes = "查询分账油企信息列表")
    public  List<Station> transactionStationList(Station station)
    {
        List<Station> stations = stationService.transactionStationList(station);
        return stations;
    }

    /**
     * 查询油站信息列表
     */
    @GetMapping("/listEnterpriseStation")
    @ApiOperation(value = "获取油站信息列表", notes = "获取油站信息列表")
    public  List<Station> listEnterpriseStation(Station station)
    {
        station.setDeleteStatus("0");
        station.setIsRepository("0");
        LoginUser current = SecurityUtils.getLoginUser();
        List<Station> stations = new ArrayList<>();
        if (null != current.getUser().getUserLevel() && current.getUser().getUserLevel().equals("2")){
            Long stationId = current.getUser().getStationId();
            station.setStationId(stationId);
            stations = stationService.selectStationList(station);
            return stations;
        }
        if (null != current.getUser().getUserLevel() && current.getUser().getUserLevel().equals("3")){
            Long stationId = current.getUser().getStationId();
            station.setStationId(stationId);
            stations = stationService.selectStationList(station);
            return stations;
        }
        if(current.getUser().getEnterpriseId()==null){
            stations = stationService.selectStationList(station);
        }else{
            station.setEnterpriseId(current.getUser().getEnterpriseId());
            stations = stationService.selectStationList(station);
        }
        List<Enterprise> enterpriseList = new ArrayList<>();
        //权限判断
        if (SecurityUtils.isPartner()) {
            if (station.getStationId() == null && station.getStationCode() == null) {
                EnterpriseAndStationVo itemIds = stationService.getItemIds(current.getUser());
                if (itemIds.getStationIdsStr() == null) {
                    throw new CustomException("未创建油站");
                } else {
                    station.setStationIdList(itemIds.getStationIdsStr());
                }
            }
        } else {
            stations = stationService.selectStationList(station);
        }
        return stations;
    }

    /**
     * 根据是否是admin获取新增时仓库列表
     */
    @GetMapping("/getRepository")
    @ApiOperation(value = "获取油站信息列表", notes = "获取油站信息列表")
    public List<Station> getRepository(Station station)
    {
        LoginUser current=SecurityUtils.getLoginUser();
        List<Station> stations = new ArrayList<>();
        if (StringUtils.isNull(current.getUser().getUserLevel())){
            Repositories repositories = new Repositories();
            BeanUtils.copyProperties(station,repositories);
            List<Repositories> list = repositoryService.selectRepositoryList(repositories);
            for (Repositories repository : list) {
                Station station1 = new Station();
                station1.setStationId(repository.getStationId());
                station1.setStationName(repository.getStationName());
                stations.add(station1);
            }
        } else {
            stations = listEnterpriseStation(station);
        }
        return stations;
    }


    /**
     * 根据是否是admin获取所有列表
     */
    @GetMapping("/getRepositoryAndStation")
    @ApiOperation(value = "获取油站信息列表", notes = "获取油站信息列表")
    public List<Station> getRepositoryAndStation(Station station)
    {
        LoginUser current=SecurityUtils.getLoginUser();
        List<Station> stations = new ArrayList<>();
        if (StringUtils.isNull(current.getUser().getUserLevel())){
//            Repositories repositories = new Repositories();
//            List<Repositories> list = repositoryService.selectRepositoryList(repositories);
//            for (Repositories repository : list) {
//                Station station1 = new Station();
//                station1.setStationId(repository.getStationId());
//                station1.setStationName(repository.getStationName());
//                stations.add(station1);
//            }
            Station req = new Station();
            req.setDeleteStatus("0");
            req.setStatus("1");
            stations.addAll(stationService.selectStationList(req));
        } else {
            stations = listEnterpriseStation(station);
        }
        return stations;
    }


    /**
     * 根据油企获取油站
     */
    @GetMapping("/getListByEnterpriseId")
    @ApiOperation(value = "获取油站信息列表", notes = "根据油企获取油站")
    public AjaxResult getListByEnterpriseId(Long enterpriseId) {
        List<Station> stationList = stationService.list(new QueryWrapper<Station>().eq("enterprise_id", enterpriseId));
        return AjaxResult.success(stationList);
    }

    /**
     * 查询油站信息列表
     */
    @GetMapping("/list")
    @ApiOperation(value = "获取油站信息列表", notes = "获取油站信息列表")
    public TableDataInfo list(Station station)
    {
        LoginUser current=SecurityUtils.getLoginUser();
        if(current.getUser().getEnterpriseId()!=null) {
        	station.setEnterpriseId(current.getUser().getEnterpriseId());
        }
        startPage();
        station.setDeleteStatus("0");
        //将地址和图片转为string
        String regionData1="";
        if (station.getRegionDataList() !=null&&station.getRegionDataList().length>0) {
            for (String regionData : station.getRegionDataList()) {
                if ("".equals(regionData1)) {
                    regionData1 += regionData;
                } else {
                    regionData1 += "," + regionData;
                }
            }
            if(!"".equals(regionData1)){
                station.setRegionData(regionData1);
            }
        }
        //权限判断
        if (SecurityUtils.isPartner()) {
            EnterpriseAndStationVo itemIds = stationService.getItemIds(current.getUser());
            if (itemIds == null||  itemIds.getStationIdsStr() == null||itemIds.getStationIdsStr().size() < 1 ) {
                throw new CustomException("未创建油站");
            } else {
                station.setStationIdList(itemIds.getStationIdsStr());
            }
        } else if ("2".equals(current.getUser().getUserLevel())) {
            station.setStationId(current.getUser().getStationId());
        }
        List<Station> stations = stationService.selectStationList(station);
        List<Station> stationlist=new ArrayList<>();
        for(int mm=0;mm<stations.size();mm++){
            if(stations.get(mm).getRegionData()!=null){
                stations.get(mm).setRegionDataList(stations.get(mm).getRegionData().split(","));
            }
            List<img>  imgs=new ArrayList<>();
            if(stations.get(mm).getImgUrl()!=null){
                String[] message= stations.get(mm).getImgUrl().split(",");
                String[] name= stations.get(mm).getImgName().split(",");

                for(int i=0;i<name.length;i++){
                    img img2=new img();
                    img2.setName(name[i]);
                    img2.setUrl(message[i]);
                    imgs.add(img2);
                }
            }
            stations.get(mm).setImgFileList(imgs);
        }

        return getDataTable(stations);
    }

    //添加油站清分信息
    @PostMapping("/addOrUpdateSettleInfo")
    @ApiOperation(value = "添加修改油站清分信息", notes = "添加修改油站清分信息")
    public AjaxResult addOrUpdateSettleInfo(@RequestBody @Valid AddStationSettleInfoDto addStationSettleInfoDto){
        stationService.addStationSettleInfo(addStationSettleInfoDto);
        return AjaxResult.success("保存成功");
    }


    @GetMapping("/getStationSettleInfo")
    @ApiOperation(value = "获取油站清分信息", notes = "获取油站清分信息")
    public AjaxResult getStationSettleInfo(@RequestParam @NotEmpty String stationId){
        return AjaxResult.success(stationService.getStationSettleInfo(stationId));
    }

    @GetMapping("/setShowCommisson")
    @ApiOperation(value = "设置是否展示渠道费1展示 0 不展示", notes = "设置是否展示渠道费1展示 0 不展示")
    public AjaxResult setShowCommisson(Station station){

        return AjaxResult.success( stationService.setShowCommisson(station));
    }

    @GetMapping("/setOpenStaffClass")
    @ApiOperation(value = "设置是否可以员工班结1可以 0 不", notes = "设置是否可以员工班结1可以 0 不")
    public AjaxResult setOpenStaffClass(Station station){

        return AjaxResult.success( stationService.setOpenStaffClass(station));
    }


    @GetMapping("/setShowPaymentCommission")
    @ApiOperation(value = "设置是否展示支付页面渠道费1展示 0 不展示", notes = "设置是否展示支付页面渠道费1展示 0 不展示")
    public AjaxResult setShowPaymentCommission(Station station){
        Station station1 = stationService.selectStationById(station.getStationId());
        Boolean b1 = (ObjectUtils.isNotEmpty(station.getCombinedPaymentFlag())&& station.getCombinedPaymentFlag().equals(1))&&(ObjectUtils.isNotEmpty(station1.getMultipleOilPayFlag())&&station1.getMultipleOilPayFlag().equals(1));
        Boolean b2 = (ObjectUtils.isNotEmpty(station.getMultipleOilPayFlag())&& station.getMultipleOilPayFlag().equals(1))&&(ObjectUtils.isNotEmpty(station1.getCombinedPaymentFlag())&&station1.getCombinedPaymentFlag().equals(1));
        if (b1 || b2) {
            return AjaxResult.error("组合支付和多油品合只能开启一个");
        }
        return AjaxResult.success( stationService.setShowPaymentCommission(station));
    }


    /**
     * 查询油站信息列表
     */
    @GetMapping("/getStationDifferent")
    public TableDataInfo getStationDifferent( Station station)
    {
        startPage();
        station.setDeleteStatus("0");
        station.setEnterpriseId(1L);
        List<Station> stations = stationService.selectStationList(station);
        for(int mm=0;mm<stations.size();mm++){
            if(stations.get(mm).getRegionData()!=null){
                stations.get(mm).setRegionDataList(stations.get(mm).getRegionData().split(","));
            }
            List<img>  imgs=new ArrayList<>();
            if(stations.get(mm).getImgUrl()!=null){
                String[] message= stations.get(mm).getImgUrl().split(",");
                String[] name= stations.get(mm).getImgName().split(",");

                for(int i=0;i<name.length;i++){
                    img img2=new img();
                    img2.setName(name[i]);
                    img2.setUrl(message[i]);
                    imgs.add(img2);
                }
            }
            stations.get(mm).setImgFileList(imgs);
        }

        return getDataTable(stations);
    }

    /**
     * 新增油站
     */
    @Log(title = "增加油站", businessType = BusinessType.INSERT)
    @PostMapping("batchInsertStations")
    public AjaxResult addStations(@RequestBody List<Station> stationList) throws Exception {
        List<StationResVo> res = stationService.batchInsertStation(stationList);
        return AjaxResult.success("新增油站成功",res);
    }

    /**
     * 新增油站或者油企
     */
    @Log(title = "增加油站", businessType = BusinessType.INSERT)
    @PostMapping("addStationOrEnterprise")
    public AjaxResult addStationOrEnterprise(@RequestBody @Valid AddStationDto addStationDto) throws Exception {
        log.info("请求入参{}",addStationDto.toString());

        if(Objects.nonNull(addStationDto.getStatus()) && !addStationDto.getStatus().equals(0) && !addStationDto.getStatus().equals(1)){
            return  AjaxResult.error("status参数错误");
        }

       if(addStationDto.getType().equals(1)){
           //新增油企
           EnterpriseVo enterpriseVo = new EnterpriseVo();

           if(Objects.isNull(addStationDto.getStatus())){
               enterpriseVo.setStatus("1");
           }

           enterpriseVo.setEnterpriseName(addStationDto.getName());
           enterpriseVo.setCopId(addStationDto.getCopId());
           enterpriseVo.setStatus(addStationDto.getStatus().toString());
           return enterpriseService.addEnterprise(enterpriseVo);

       }else if(addStationDto.getType().equals(2)){
           if(StringUtils.isEmpty(addStationDto.getpCode())){
               return  AjaxResult.error("type为2时，pCode不能为空");
           }

           //油企ID
           Enterprise enterprise = new Enterprise();
           enterprise.setEnterpeiseCode(addStationDto.getpCode());
           List<Enterprise> enterprises = enterpriseService.selectEnterpriseList(enterprise);
           if(CollectionUtils.isEmpty(enterprises)){
               return AjaxResult.error("油企不存在");
           }

           //新增油站
           StationVo stationVo = new StationVo();
           stationVo.setStationName(addStationDto.getName());
           stationVo.setEnterpriseId(enterprises.get(0).getEnterpriseId());
           stationVo.setCopId(addStationDto.getCopId());
           stationVo.setStatus(addStationDto.getStatus().toString());
           if(Objects.isNull(addStationDto.getStatus())){
               stationVo.setStatus("1");
           }
           return stationService.addStation(stationVo);
       }
        return AjaxResult.error("新增失败");
    }


    /**
     * 新增油站
     */
    @Log(title = "增加油站", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Station station)
    {
        System.out.println("新增--------------");
        int m=0;
        Calendar cal = Calendar.getInstance();
        String regionData1="";
//        String licenseImg="";
//        String ImgName="";
        if (station.getRegionDataList() !=null&&station.getRegionDataList().length>0) {
            for (String regionData : station.getRegionDataList()) {
                if ("".equals(regionData1)) {
                    regionData1 += regionData;
                } else {
                    regionData1 += "," + regionData;
                }
            }

            if (!"".equals(regionData1)) {
                station.setRegionData(regionData1);
            }
        }
        // 轮播图不需要
//        if (station.getImgFileList()!=null&&station.getImgFileList().size()>0) {
//            for (img img1 : station.getImgFileList()) {
//                if ("".equals(licenseImg)) {
//                    licenseImg += img1.getUrl();
//                    ImgName +=img1.getName();
//                } else {
//                    licenseImg +="," +img1.getUrl();
//                    ImgName +=","+img1.getName();
//                }
//            }
//
//            if (!"".equals(licenseImg)) {
//                station.setImgUrl(licenseImg);
//                station.setImgName(ImgName);
//            }
//        }
        Random random=new Random();
        String result1 = "";
        for (int i = 0; i < 4; i++) {
            result1 += random.nextInt(10);
        }
        int year = cal .get(Calendar.YEAR);
        int month = cal .get(Calendar.MONTH) + 1;
        int yearcount=year-2000;
        String code="S"+yearcount+month+"0001"+result1;
        station.setStationCode(code);
        m=stationService.insertStation(station);

        if(m<=0){
           return  toAjax(0);

        }
        Long[] roles={Long.parseLong(19+"")};
        //Station station1=stationService.selectStationList(station).get(0);
        SysUser sysUser=new SysUser();
        sysUser.setDeptId((long) 100);
        sysUser.setUserName(code);
        sysUser.setNickName(station.getStationName());
        sysUser.setUserLevel("2");
        sysUser.setPhonenumber(station.getPhone());
        sysUser.setPassword(SecurityUtils.encryptPassword("123456"));
        sysUser.setStationId(station.getStationId());
        sysUser.setRoleIds(roles);
        sysUser.setEnterpriseId(station.getEnterpriseId());
        sysUser.setAuthLevel("3");
        sysUser.setAuthorId(SecurityUtils.getLoginSysUser().getUserId());
        SysUser aSysUser =  userMapper.selectUserById(SecurityUtils.getLoginSysUser().getUserId());

        if(aSysUser.getUserLevel()==null || aSysUser.getUserLevel().equals("7")){
            sysUser.setSupremeLevelName(aSysUser.getUserName());
        }else{
            sysUser.setSupremeLevelName(aSysUser.getSupremeLevelName());
        }
        return toAjax(  sysUserService.insertUser(sysUser));
    }

    /**
     * 新增油企
     */
    @Log(title = "增加油站下的支付方式", businessType = BusinessType.INSERT)
    @PostMapping("/addPayWay")
    public AjaxResult addPayWay(@RequestBody Station station) {
        int  i=0;
        PayWayStationBetween payWayStationBetween=new PayWayStationBetween();
        List<PayWayStationBetween> payWayStationBetweens=new ArrayList<>();
          if(station.getPayWayIdList() !=null&&station.getStationId()!=null ){
              payWayStationBetween.setStationId(station.getStationId());
              List<PayWayStationBetween>  stationBetweens=payStationBetweenService.selectPayWayStationBetweenList(payWayStationBetween) ;
              if(stationBetweens.size()>0){
                  List<PayWay> payWay=payWayService.selectPayWayByIds(stationBetweens.stream().map(PayWayStationBetween::getPayWayId).toArray(Long[]::new));
                  Long stationId = stationBetweens.get(0).getStationId();
                  for (PayWay way : payWay) {
                      redisCache.deleteObject("EnterpriseServiceImpl_selectStaPayWay::" + "s_" + stationId + "a_" + way.getAppType() + "u_" + way.getUseType());
                  }

                  Long[] array = stationBetweens.stream().map(PayWayStationBetween::getPayStationId).toArray(Long[]::new);
                  payStationBetweenService.deletePayWayStationBetweenByIds(array);
              }

//              for (PayWayStationBetween payWayStationBetween1:stationBetweens){
//                  PayWay payWay=payWayService.selectPayWayById(payWayStationBetween1.getPayWayId());
//                  redisCache.deleteObject("EnterpriseServiceImpl_selectStaPayWay::" + "s_" + payWayStationBetween1.getStationId() + "a_" + payWay.getAppType() + "u_" + payWay.getUseType());
//                  //redisCache.deleteObject("EnterpriseServiceImpl_selectStaPayWay::"+"i_null"  + "s_" + payWayStationBetween1.getStationId() + "a_" + payWay.getAppType() + "u_" + payWay.getUseType());
//                  i= payStationBetweenService.deletePayWayStationBetweenById(payWayStationBetween1.getPayStationId());
//
//              }
              int  j= payStationBetweenService.deleteAutoPayWayOver(station.getStationId());
              System.out.println("删除信息成功");
              for(Long mm:station.getPayWayIdList()){

                  PayWayStationBetween payWayStationBetween2=new PayWayStationBetween();
                  payWayStationBetween2.setStationId(station.getStationId());
                  payWayStationBetween2.setPayWayId(mm);
                  payWayStationBetweens.add(payWayStationBetween2);
              }

          }
        try {
            i= payStationBetweenService.addPayWayStationBetweenList(payWayStationBetweens);
          int  j= payStationBetweenService.insertAutoPayWayOver(payWayStationBetweens);


        } catch (Exception e) {
            return toAjax(0);
        }
        //更新油站修改时间
        Station updateStation = new Station();
        updateStation.setStationId(station.getStationId());
        stationService.updateStation(updateStation);

        return toAjax(i);
    }
//复制增加油站下的支付方式接口调用
    public AjaxResult autoPayWay(@RequestBody Station station) {
        int  i=0;
        PayWayStationBetween payWayStationBetween=new PayWayStationBetween();
        List<PayWayStationBetween> payWayStationBetweens=new ArrayList<>();
        if(station.getPayWayIdList() !=null&&station.getStationId()!=null ){
            payWayStationBetween.setStationId(station.getStationId());
            List<PayWayStationBetween>  stationBetweens=payStationBetweenService.selectPayWayStationBetweenList(payWayStationBetween) ;
            for (PayWayStationBetween payWayStationBetween1:stationBetweens){
                PayWay payWay=payWayService.selectPayWayById(payWayStationBetween1.getPayWayId());
                redisCache.deleteObject("EnterpriseServiceImpl_selectStaPayWay::" + "s_" + payWayStationBetween1.getStationId() + "a_" + payWay.getAppType() + "u_" + payWay.getUseType());
                //redisCache.deleteObject("EnterpriseServiceImpl_selectStaPayWay::"+"i_null"  + "s_" + payWayStationBetween1.getStationId() + "a_" + payWay.getAppType() + "u_" + payWay.getUseType());
                i= payStationBetweenService.deletePayWayStationBetweenById(payWayStationBetween1.getPayStationId());
            }
            System.out.println("删除信息成功");
            for(Long mm:station.getPayWayIdList()){

                PayWayStationBetween payWayStationBetween2=new PayWayStationBetween();
                payWayStationBetween2.setStationId(station.getStationId());
                payWayStationBetween2.setPayWayId(mm);
                payWayStationBetweens.add(payWayStationBetween2);
            }

        }
        try {
            i= payStationBetweenService.addPayWayStationBetweenList(payWayStationBetweens);
        } catch (Exception e) {
            return toAjax(0);
        }
        //更新油站修改时间
        Station updateStation = new Station();
        updateStation.setStationId(station.getStationId());
        stationService.updateStation(updateStation);

        return toAjax(i);
    }


    /**
     * 逻辑删除
     */
    @PostMapping(value = "/deleteStation")
    public AjaxResult deleteStation(@RequestBody Station station)
    {
        if(station.getStationId()==null){
            return AjaxResult.error("stationId不能为空");
        }

        return  AjaxResult.success(stationService.logicallyDelete(station.getStationId()));
    }


    /**
     * 获取油站信息详细信息
     */
    @GetMapping(value = "/{stationId}")
    public AjaxResult getInfo(@PathVariable("stationId") Long stationId)
    {
        Station station=stationService.selectStationById(stationId);
        if(station.getRegionData()!=null) {
            station.setRegionDataList(station.getRegionData().split(","));
        }
        List<img>  imgs=new ArrayList<>();
        if(station.getImgUrl()!=null){
            String[] message= station.getImgUrl().split(",");
            String[] name= station.getImgName().split(",");

            for(int i=0;i<name.length;i++){
                img img2=new img();
                img2.setName(name[i]);
                img2.setUrl(message[i]);
                imgs.add(img2);
            }
        }
        station.setImgFileList(imgs);
        return AjaxResult.success(station);
    }

    /**
     * 修改油站信息
     */
    @Log(title = "油站信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Station station)
    {
        System.out.println("修改--------------");


        if ( StringUtils.equals("1",station.getNeedStaff())) {
            StaffVO staffVO = new StaffVO();
            staffVO.setStationId(station.getStationId());
            staffVO.setUserLevel(UserConstants.LEVEL_THREE);
            long total = staffService.countStaffNum(staffVO);
            if (total==0) {
                throw new CustomException(ErrorCode.STATION_NO_STAFF);
            }
        }

        String regionData1="";
        String licenseImg="";
        String ImgName="";
        if (station.getRegionDataList() !=null&&station.getRegionDataList().length>0) {
            for (String regionData : station.getRegionDataList()) {
                if ("".equals(regionData1)) {
                    regionData1 += regionData;
                } else {
                    regionData1 += "," + regionData;
                }
            }

            if (!"".equals(regionData1)) {
                station.setRegionData(regionData1);
            }
        }
        if (station.getImgFileList()!=null&&station.getImgFileList().size()>0) {
            for (img img1 : station.getImgFileList()) {
                if ("".equals(licenseImg)) {
                    licenseImg += img1.getUrl();
                    ImgName +=img1.getName();
                } else {
                    licenseImg +="," +img1.getUrl();
                    ImgName +=","+img1.getName();
                }
            }

            if (!"".equals(licenseImg)) {
                station.setImgUrl(licenseImg);
                station.setImgName(ImgName);
            }
        }
        SysUser sysUser=new SysUser();
        sysUser.setStationId(station.getStationId());
        List<SysUser> sysUserList= sysUserService.selectUserList(sysUser);
        if(sysUserList!=null && sysUserList.size()>0){
         for(SysUser sysUser1:sysUserList){
             sysUser1.setEnterpriseId(station.getEnterpriseId());
             sysUserService.updateUserProfile(sysUser);
         }
        }
        redisCache.deleteObject("EnterpriseServiceImpl_selectStaInfoList::" + "e_" +station.getEnterpriseId() );
        redisCache.deleteObject("EnterpriseServiceImpl_selectStaOilGunList::" + "s_" +station.getStationId() );
        redisCache.deleteObject("EnterpriseServiceImpl_selectStationById::" + "s_" +station.getStationId() );
        redisCache.deleteObject("EnterpriseServiceImpl_selectEnterpriseInfo::" + "e_" +station.getEnterpriseId() );
        return toAjax(stationService.updateStation(station));
    }
    @ApiOperation(value = "调整油价获取油站", notes = "调整油价获取油站")
    @GetMapping("/getStationInfo")
    public AjaxResult getStationInfo() {
        return AjaxResult.success(stationService.getStationInfo());
    }


}
